<?

//Initiate Authenticate
SecurityRedirect ();

//initiate Vars
define("PRIMARY_KEY","kdvendor");
$KEY[]         = array("PRIMARY_KEY"=>PRIMARY_KEY);
$FileName      = "ais_transaction_vendorlist.php";
$FormName            = GetParam("FormName","");
if (GetParam("Template","")=="DN") $FileTemplate  = "ais_transaction_vendorlist_dnlist.html";
elseif ((GetParam("FormName","")=="MemorialTransForm") && !GetParam("SendToBack","")) {$FileTemplate = "ais_transaction_vendorlist_memotrans.html";}
elseif ((GetParam("FormName","")=="CashBankForm") && !GetParam("SendToBack","")) {$FileTemplate = "ais_transaction_vendorlist_cashbanktrans.html";}
elseif ((GetParam("FormName","")=="CashBankPaymentForm") && !GetParam("SendToBack","")) {$FileTemplate = "ais_transaction_vendorlist_cashbanktrans_pay.html";}
else $FileTemplate  = "ais_transaction_vendorlist_list.html";
$PageSize      = 10 ;
$HTMLGridList  = "VendorGrid";
//************ FORM ACTION **************
    if (GetParam("Action","")=="Delete") {
        DeleteRecord ("txtCheck",$PageSize);
    }

//Initiate Database Table For Search;
$FNama = GetParam("vendorSearch","");
$FCode = GetParam("vendorCodeSearch","");
$FDate = GetParam("transDate","");
$curr   = GetParam("curr","");

//******* DATABASE FORM QUERY ***********
$SQL = "SELECT * FROM `tblvendor` ";
$SQLCount = "SELECT count(*) FROM `tblvendor` ";

if ($FNama)
    if (strlen($WHERE)) $WHERE .= " AND "." nama like '".GetParam("vendorSearch","")."%'";
    else $WHERE .= " nama like '".GetParam("vendorSearch","")."%'";
if ($FCode)
    if (strlen($WHERE)) $WHERE .= " AND "." kdvendor like '".GetParam("vendorCodeSearch","")."%'";
    else $WHERE .= " kdvendor like '".GetParam("vendorCodeSearch","")."%'";

    if (strlen($WHERE)) $WHERE = " WHERE ".$WHERE;
    else $WHERE = " WHERE 1";

$SQL = $SQL.$WHERE." ORDER BY kdvendor";
//print $SQL;
//******* SHOW FORM CONTENT *********
$SQLCount = $SQLCount.$WHERE;
$PageNum = 1;
$RecCnt = $DBConnection->dbc->get_var($SQLCount) ;

if (GetParam("PageNum","")) $PageNum  = GetParam("PageNum","");

$TBS = new clsTinyButStrong ;
$TBS->LoadTemplate($MOD_TEMPLATE_DIR."/".$FileTemplate);
$TBS->MergeBlock("bln",$KEY);
$TBS->MergeBlock("blg",$DBMysql,$SQL,$PageSize,$PageNum,$RecCnt);
$TBS->MergeNavigationBar('nv',array('size'=>10,'pos'=>'centred'),$PageNum,$RecCnt,$PageSize) ;
$TBS->Show();


function DeleteRecord ($sequence_name,$PageSize) {
    global $DBConnection,$FileName;
    for ($x=1;$x<=$PageSize;$x++) {
        if (GetParam($sequence_name.$x,"")) {
            $DBConnection->Delete("tblvendor",$sequence_name.$x);
        }
    }
    header("Location: $FileName");
    exit;

}

?>
